﻿
using SqlSugar;

namespace DADAL
{
    /// <summary>
    /// 设备点位
    ///</summary>
    [SugarTable("c_device_point")]
    public class DevicePointModel
    {

        /// <summary>
        /// 备  注:点位编号
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "number", IsPrimaryKey = true)]
        public int Number { get; set; }

        /// <summary>
        /// 备  注:点位名称
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "name")]
        public string Name { get; set; } = null!;

        /// <summary>
        /// 备  注:点位地址
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "address")]
        public string Address { get; set; } = null!;

        /// <summary>
        /// 备  注:点位类型
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "point_type")]
        public string PointType { get; set; } = null!;

        /// <summary>
        /// 备  注:量程最小
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "range_min")]
        public double RangeMin { get; set; }

        /// <summary>
        /// 备  注:量程最大
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "range_max")]
        public double RangeMax { get; set; }

        /// <summary>
        /// 备  注:输出最小
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "out_min")]
        public double OutMin { get; set; }

        /// <summary>
        /// 备  注:输出最大
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "out_max")]
        public double OutMax { get; set; }

        /// <summary>
        /// 备  注:报警最小
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "alarm_min")]
        public double AlarmMin { get; set; }

        /// <summary>
        /// 备  注:报警最大
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "alarm_max")]
        public double AlarmMax { get; set; }

        /// <summary>
        /// 备  注:误差范围
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "error_range")]
        public double ErrorRange { get; set; }

        /// <summary>
        /// 备  注:修正值
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "amend")]
        public double Amend { get; set; }

        /// <summary>
        /// 备  注:单位
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "unit")]
        public string Unit { get; set; } = null!;

        /// <summary>
        /// 备  注:设备编号
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "device_number")]
        public int DeviceNumber { get; set; }

        /// <summary>
        /// 备  注:设备名称
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "device_name")]
        public string DeviceName { get; set; } = null!;

        /// <summary>
        /// 备  注:设备地址
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "device_address")]
        public string DeviceAddress { get; set; } = null!;

        /// <summary>
        /// 根据点位名判断是否存在
        /// </summary>
        /// <param name="name">点位名称</param>
        /// <param name="deviceNumber">设备编号</param>
        /// <returns></returns>
        public static bool RecordExistenceWithName(string name, int deviceNumber)
        {
            Dictionary<string, Object> where = new Dictionary<string, Object>();
            where["name"] = name;
            where["device_number"] = deviceNumber;
            List<DevicePointModel> list = SqlSugarHelper.Inquireable<DevicePointModel>(where);
            if (list.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 根据编号判断是否存在
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public static bool RecordExistenceWithNumber(int number)
        {
            Dictionary<string, Object> where = new Dictionary<string, Object>();
            where["number"] = number;
            List<DevicePointModel> list = SqlSugarHelper.Inquireable<DevicePointModel>(where);
            if (list.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

}
